package l1j.opqlo.NewSystem;

import java.util.TimerTask;
import java.util.logging.Level;
import java.util.logging.Logger;

import l1j.opqlo.Server.L1World.L1World;
import l1j.server.server.model.L1Object;
import l1j.server.server.model.Instance.L1MonsterInstance;
import l1j.server.server.model.Instance.L1PcInstance;
import l1j.server.server.serverpackets.S_DoActionGFX;
import l1j.server.server.serverpackets.S_SkillSound;

public class BulajiaMagic extends TimerTask {
	private static Logger _log = Logger.getLogger(BulajiaMagic.class.getName());

	private final L1PcInstance Active_pc;

	public BulajiaMagic(L1PcInstance pc) {
		this.Active_pc = pc;
	}

	@Override
	public void run() {
		try {
			if (this.Active_pc.isDead()) {
				// Active_pc.stopBulajiaMagic();
				return;
			}
			// S_SkillSound sound =new S_SkillSound(Active_pc.getId(),
			// effect_id);
			// Active_pc.sendPackets(sound);
			// Active_pc.broadcastPacket(sound); // 是否加入，請自行考量

			for (final L1Object cha : L1World.getInstance().getVisibleObjects(
					this.Active_pc, 5)) {

				if (cha instanceof L1MonsterInstance) {
					final L1MonsterInstance mon = (L1MonsterInstance) cha;
					if (mon.getCurrentHp() <= 1) {
						continue;
					}
					final S_SkillSound sound = new S_SkillSound(cha.getId(),
							2568);
					// Active_pc.sendPackets(sound);
					mon.broadcastPacketAll(sound); // 是否加入，請自行考量
					mon.broadcastPacketAll(new S_DoActionGFX(mon.getId(), 2)); //
					final int hp = mon.getCurrentHp() - 500;
					if (hp <= 1) {
						mon.setCurrentHp(1);
					} else {
						mon.setCurrentHp(hp);
					}
					// L1SkillUse l1skilluse = new L1SkillUse();
					// l1skilluse.handleCommands(Active_pc, 14127, targetId,
					// targetX, targetY,"", 0, 0);

				}

			}
			/*
			 * L1SkillUse l1skilluse = new L1SkillUse();
			 * l1skilluse.handleCommands(Active_pc, 14127, Active_pc.getId(),
			 * Active_pc.getX(), Active_pc.getY(),"", 0,
			 * L1SkillUse.TYPE_GMBUFF);
			 */

		} catch (final Throwable e) {
			_log.log(Level.WARNING, e.getLocalizedMessage(), e);
		}
	}
}